package p270jp.pxv.android.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import java.util.Arrays;
import java.util.Locale;
import p064c6.Preconditions;
import p134ei.AnalyticsAction;
import p134ei.AnalyticsScreenName;
import p134ei.LikeButtonAnalytics;
import p134ei.PixivAnalytics;
import p159fi.FirebaseAnalyticsEvent;
import p165fo.C3114c;
import p165fo.Subscribe;
import p184gi.AnalyticsParameter;
import p184gi.FirebaseAnalyticsEventName;
import p184gi.LikeEvent;
import p189gn.AbstractC3435a;
import p216hn.Lambda;
import p216hn.Reflection;
import p270jp.pxv.android.event.UpdateLikeEvent;
import p270jp.pxv.android.legacy.model.PixivIllust;
import p270jp.pxv.android.legacy.model.PixivNovel;
import p270jp.pxv.android.legacy.model.PixivWork;
import p270jp.pxv.android.model.BrowsingHistoryDaoManager;
import p325m0.MutabilityOwnership;
import p346ml.MyWorkService;
import p347mm.WorkUtils;
import p374nm.C5387b0;
import p376no.Koin;
import p404oo.AbstractC5475a;
import p579vo.Qualifier;
import p603wm.AbstractC6949c;
import p671zc.CompositeDisposable;

/* compiled from: LikeButton.kt */
/* renamed from: jp.pxv.android.view.LikeButton */
/* loaded from: classes2.dex */
public final class LikeButton extends C5387b0 implements LikeButtonView, LikeButtonAnalytics, View.OnClickListener, View.OnLongClickListener, AbstractC5475a {

    /* renamed from: e */
    public PixivWork f19536e;

    /* renamed from: j */
    public AnalyticsParameter f19541j;

    /* renamed from: d */
    public final CompositeDisposable f19535d = new CompositeDisposable();

    /* renamed from: f */
    public AnalyticsAction f19537f = AnalyticsAction.DISLIKE_VIA_LIST;

    /* renamed from: g */
    public final AbstractC6949c f19538g = Preconditions.m9802P(1, new C4375a(this, null, null));

    /* renamed from: h */
    public final AbstractC6949c f19539h = Preconditions.m9802P(1, new C4376b(this, null, null));

    /* renamed from: i */
    public final AbstractC6949c f19540i = Preconditions.m9802P(1, new C4377c(this, null, null));

    /* renamed from: k */
    public FirebaseAnalyticsEventName f19542k = FirebaseAnalyticsEventName.LIKE_VIA_LIST;

    /* compiled from: KoinComponent.kt */
    /* renamed from: jp.pxv.android.view.LikeButton$a */
    /* loaded from: classes2.dex */
    public static final class C4375a extends Lambda implements AbstractC3435a<PixivAnalytics> {

        /* renamed from: a */
        public final /* synthetic */ AbstractC5475a f19543a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4375a(AbstractC5475a aVar, Qualifier aVar2, AbstractC3435a aVar3) {
            super(0);
            this.f19543a = aVar;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [ei.e, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final PixivAnalytics invoke() {
            return this.f19543a.getKoin().f24118a.m920a().m621a(Reflection.m5499a(PixivAnalytics.class), null, null);
        }
    }

    /* compiled from: KoinComponent.kt */
    /* renamed from: jp.pxv.android.view.LikeButton$b */
    /* loaded from: classes2.dex */
    public static final class C4376b extends Lambda implements AbstractC3435a<WorkUtils> {

        /* renamed from: a */
        public final /* synthetic */ AbstractC5475a f19544a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4376b(AbstractC5475a aVar, Qualifier aVar2, AbstractC3435a aVar3) {
            super(0);
            this.f19544a = aVar;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [mm.x, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final WorkUtils invoke() {
            return this.f19544a.getKoin().f24118a.m920a().m621a(Reflection.m5499a(WorkUtils.class), null, null);
        }
    }

    /* compiled from: KoinComponent.kt */
    /* renamed from: jp.pxv.android.view.LikeButton$c */
    /* loaded from: classes2.dex */
    public static final class C4377c extends Lambda implements AbstractC3435a<MyWorkService> {

        /* renamed from: a */
        public final /* synthetic */ AbstractC5475a f19545a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4377c(AbstractC5475a aVar, Qualifier aVar2, AbstractC3435a aVar3) {
            super(0);
            this.f19545a = aVar;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [ml.a, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final MyWorkService invoke() {
            return this.f19545a.getKoin().f24118a.m920a().m621a(Reflection.m5499a(MyWorkService.class), null, null);
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public LikeButton(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        MutabilityOwnership.m3745m(context, "context");
        setOnClickListener(this);
        setOnLongClickListener(this);
    }

    private final MyWorkService getMyWorkService() {
        return (MyWorkService) this.f19540i.getValue();
    }

    private final PixivAnalytics getPixivAnalytics() {
        return (PixivAnalytics) this.f19538g.getValue();
    }

    private final WorkUtils getWorkUtils() {
        return (WorkUtils) this.f19539h.getValue();
    }

    @Override // p134ei.LikeButtonAnalytics
    /* renamed from: a */
    public void mo4492a() {
        PixivAnalytics.m6529a(getPixivAnalytics(), 2, this.f19537f, null, 4);
    }

    @Override // p134ei.LikeButtonAnalytics
    /* renamed from: c */
    public void mo4491c() {
        AnalyticsParameter cVar;
        FirebaseAnalyticsEvent aVar;
        PixivWork pixivWork = this.f19536e;
        if (pixivWork != null && (cVar = this.f19541j) != null) {
            FirebaseAnalyticsEventName jVar = this.f19542k;
            if (pixivWork instanceof PixivIllust) {
                switch (jVar.ordinal()) {
                    case 14:
                        aVar = new LikeEvent.C3348d(pixivWork.f19079id, cVar.f15553b, cVar.f15552a);
                        break;
                    case 15:
                        aVar = new LikeEvent.C3347c(pixivWork.f19079id, cVar.f15553b, cVar.f15552a);
                        break;
                    case 16:
                        aVar = new LikeEvent.C3345a(pixivWork.f19079id, cVar.f15553b, cVar.f15552a);
                        break;
                    case 17:
                        aVar = new LikeEvent.C3346b(pixivWork.f19079id, cVar.f15553b, cVar.f15552a);
                        break;
                    default:
                        throw new IllegalStateException();
                }
            } else if (pixivWork instanceof PixivNovel) {
                switch (jVar.ordinal()) {
                    case 14:
                        aVar = new LikeEvent.C3352h(pixivWork.f19079id, cVar.f15553b, cVar.f15552a, cVar.f15554c);
                        break;
                    case 15:
                        aVar = new LikeEvent.C3351g(pixivWork.f19079id, cVar.f15553b, cVar.f15552a, cVar.f15554c);
                        break;
                    case 16:
                        aVar = new LikeEvent.C3349e(pixivWork.f19079id, cVar.f15553b, cVar.f15552a, cVar.f15554c);
                        break;
                    case 17:
                        aVar = new LikeEvent.C3350f(pixivWork.f19079id, cVar.f15553b, cVar.f15552a, cVar.f15554c);
                        break;
                    default:
                        throw new IllegalStateException();
                }
            } else {
                throw new IllegalStateException();
            }
            getPixivAnalytics().m6526d(aVar);
        }
    }

    @Override // p270jp.pxv.android.view.LikeButtonView
    public void disabledView() {
        setEnabled(false);
    }

    @Override // p270jp.pxv.android.view.LikeButtonView
    public void enabledView() {
        setEnabled(true);
    }

    /* renamed from: f */
    public final void m4490f(boolean z, boolean z2, PixivWork pixivWork) {
        String str;
        if (z2) {
            m3335b(z);
        } else {
            m3333e(z);
        }
        if (this.f24020a.f22034u.getVisibility() == 0) {
            TextView textView = this.f24020a.f22034u;
            int i = pixivWork.totalBookmarks;
            if (1000 <= i) {
                str = String.format(Locale.US, "%d.%dK", Arrays.copyOf(new Object[]{Integer.valueOf(i / BrowsingHistoryDaoManager.MAX_RECORDS), Integer.valueOf((pixivWork.totalBookmarks % BrowsingHistoryDaoManager.MAX_RECORDS) / 100)}, 2));
                MutabilityOwnership.m3746l(str, "java.lang.String.format(locale, format, *args)");
            } else {
                str = String.valueOf(i);
            }
            textView.setText(str);
        }
    }

    @Override // p404oo.AbstractC5475a
    public Koin getKoin() {
        return AbstractC5475a.C5476a.m3211a(this);
    }

    @Override // android.view.View, android.view.ViewGroup
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        C3114c.m6284b().m6276j(this);
    }

    @Override // android.view.View.OnClickListener
    public void onClick(View view) {
        MutabilityOwnership.m3745m(view, "v");
        WorkUtils workUtils = getWorkUtils();
        PixivWork pixivWork = this.f19536e;
        MutabilityOwnership.m3747j(pixivWork);
        workUtils.m3531c(pixivWork, this.f19535d, this, this);
    }

    @Override // android.view.View, android.view.ViewGroup
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.f19535d.m80f();
        C3114c.m6284b().m6274l(this);
    }

    @Subscribe
    public final void onEvent(UpdateLikeEvent updateLikeEvent) {
        MutabilityOwnership.m3745m(updateLikeEvent, "event");
        PixivWork pixivWork = this.f19536e;
        if (pixivWork != null && getWorkUtils().m3533a(pixivWork) == getWorkUtils().m3533a(updateLikeEvent.getWork()) && updateLikeEvent.getWorkId() == pixivWork.f19079id) {
            boolean isBookmarked = updateLikeEvent.isBookmarked();
            pixivWork.isBookmarked = isBookmarked;
            m4490f(isBookmarked, false, pixivWork);
        }
    }

    @Override // android.view.View.OnLongClickListener
    public boolean onLongClick(View view) {
        AnalyticsScreenName cVar;
        MutabilityOwnership.m3745m(view, "v");
        AnalyticsParameter cVar2 = this.f19541j;
        if (cVar2 == null) {
            cVar = null;
        } else {
            cVar = cVar2.f15552a;
        }
        if (cVar == null) {
            return false;
        }
        WorkUtils workUtils = getWorkUtils();
        PixivWork pixivWork = this.f19536e;
        MutabilityOwnership.m3747j(pixivWork);
        return workUtils.m3532b(pixivWork, cVar);
    }

    public final void setAnalyticsParameter(AnalyticsParameter cVar) {
        MutabilityOwnership.m3745m(cVar, "parameter");
        this.f19541j = cVar;
    }

    public final void setDislikeAnalyticsAction(AnalyticsAction aVar) {
        MutabilityOwnership.m3745m(aVar, "dislikeAction");
        this.f19537f = aVar;
    }

    public final void setLikeEventName(FirebaseAnalyticsEventName jVar) {
        MutabilityOwnership.m3745m(jVar, "eventName");
        this.f19542k = jVar;
    }

    public final void setWork(PixivWork pixivWork) {
        MutabilityOwnership.m3745m(pixivWork, "work");
        this.f19536e = pixivWork;
        setVisibility((getMyWorkService().m3554a(pixivWork) || (!pixivWork.visible && !pixivWork.isBookmarked)) ? 4 : 0);
        m4490f(pixivWork.isBookmarked, false, pixivWork);
    }

    @Override // p270jp.pxv.android.view.LikeButtonView
    public void updateViewWithDisliked() {
        PixivWork pixivWork = this.f19536e;
        if (pixivWork != null) {
            m4490f(false, true, pixivWork);
        }
    }

    @Override // p270jp.pxv.android.view.LikeButtonView
    public void updateViewWithLiked() {
        PixivWork pixivWork = this.f19536e;
        if (pixivWork != null) {
            m4490f(true, true, pixivWork);
        }
    }
}
